package me.landery.modules.sinco.domain;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import me.landery.base.BaseEntity;
import me.landery.modules.system.domain.User;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @Author cc.ws
 * @Date 2022/6/7 16:03
 * @Version 1.0
 */
@Entity
@Getter
@Setter
@Table(name="sinco_order")
public class Order extends BaseEntity implements Serializable {
    @Id
    @Column(name = "oid")
    @NotNull(groups = BaseEntity.Update.class)
    @ApiModelProperty(value = "订单ID", hidden = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id; //订单id

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name = "uid")
    private User user; //用户id

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name = "pid")
    private Mode mode; //套餐id


    @ApiModelProperty(value = "订单总数量")
    private Integer quantity;

    @ApiModelProperty(value = "订单总价格")
    private Double price;

    @Column(name = "time")
    @ApiModelProperty(value = "订单产生时间", hidden = true)
    private Date time;


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Order order = (Order) o;
        return Objects.equals(id, order.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

}
